<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="main" style="width: 800px; height: 600px"></div>
    <script src="./lib/echarts.min.js"></script>
    <script>
      const myChart = echarts.init(document.getElementById('main'))

      const option = {
        // 标题
        title: {
          text: '数据对比图',
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
          },
        },
        // 图列组件
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        // x轴设置
        xAxis: {
          type: 'category',
          data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
          // 线段设置
          axisLine: {
            // 线的样式
            lineStyle: {
              type: 'dashed',
              color: 'red',
            },
          },
        },
        yAxis: {
          type: 'value',
          // 分割线设置
          splitLine: {
            // 线的样式
            lineStyle: {
              type: 'dashed',
              color: '#d4d4d6',
            },
          },
        },
        // 颜色
        color: [
          // 渐变
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: '#f6e6bc', // 0% 处的颜色
              },
              {
                offset: 1,
                color: '#ef33b1', // 100% 处的颜色
              },
            ],
            global: false, // 缺省为 false
          },
          {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: '#1de5e2', // 0% 处的颜色
              },
              {
                offset: 1,
                color: '#b588f7', // 100% 处的颜色
              },
            ],
            global: false, // 缺省为 false
          },
        ],
        series: [
          // 柱状图 给多个图形,会有柱形
          {
            name: '上午',
            data: [120, 200, 150, 80, 70, 110, 130],
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)',
            },
          },
          {
            name: '下午',
            data: [140, 200, 150, 80, 70, 110, 130],
            type: 'bar',
            showBackground: true,
            backgroundStyle: {
              color: 'rgba(180, 180, 180, 0.2)',
            },
          },
        ],
      }

      myChart.setOption(option)
    </script>
  </body>
</html>
